/**
 * @param {HTMLElement} el
 * @returns {Object}
 */
export function getElementOffset(el: HTMLElement): { top: number; left: number } {
  if (!el) return { top: 0, left: 0 }
  try {
    let top = 0
    let left = 0
    let current: HTMLElement | null = el

    while (current) {
      top += current.offsetTop
      left += current.offsetLeft
      current = current.offsetParent as HTMLElement | null
    }

    return { top, left }
  } catch (e) {
    return { top: 0, left: 0 }
  }
} 